package com.example.fuzzy;

 
public class FuncionMembresia 
{
	private String name;
	private double[] valorEjeX;

	
public double  fuzzificacion(double valor) 
{
	if(valor<valorEjeX[0] || valor>valorEjeX[3])	
		return 0;

	if(valor>=valorEjeX[1] && valor<=valorEjeX[2])	
		return 1;

	if(valor>=valorEjeX[0] && valor<valorEjeX[1])	
		return	(valor-valorEjeX[0])/(valorEjeX[1]-valorEjeX[0]);
	
	if(valor>valorEjeX[2] && valor<= valorEjeX[3])	
		return (valorEjeX[3]-valor)/(valorEjeX[3]-valorEjeX[2]);

	return 0;
}
 
public String getName() 
{
	return name;
}
 
public double[] getRange() 
{
	return valorEjeX;
}
 
public FuncionMembresia(String name_in, double [] range_in) 
{
	super();
	this.name = name_in;
	this.valorEjeX = range_in;
}
 
public double [] plot(double from, double to, int size) 
{
	double increment = Math.abs((to-from)/size);
	
	double [] temp = new double [size];

	for(int i=0; i<size; i++)
		temp[i]=this.fuzzificacion(from+increment*i);
	
	return temp;
}
}
